/****************************************************
 * Description: Controllar for 不在某用户组里的用户
 * Copyright:   Copyright (c) 2013
 * Company:     beiwaionline
 * @author      bfsu
 * @version     1.0
 * @see
	HISTORY
	*  2013-08-08 bfsu wangcj File
**************************************************/

package com.bfsuol.bfsuolframework.security.controller;

import com.bfsuol.bfsuolframework.core.controller.SpringControllerSupport;
import com.bfsuol.bfsuolframework.core.controller.support.Pagination;
import com.bfsuol.bfsuolframework.security.annotations.SecFunction;
import com.bfsuol.bfsuolframework.security.service.BaseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/components/security/userNotGroup")
public class UserNotGroupController extends SpringControllerSupport {

    @Autowired
    private BaseUserService baseUserService;

    @SecFunction(title="组用户设置",privilege="components.security.group",code="userSetting")
	@RequestMapping("/index/{groupId}")
	public ModelAndView index(
			@PathVariable("groupId") Long groupId,
			Model model){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName(getViewNamedPath("index"));
		return modelAndView;
	}

    @SecFunction(title="组用户设置",privilege="components.security.group",code="userSetting")
	@RequestMapping("/list/{groupId}")
	public ModelAndView list(
			@PathVariable("groupId") Long groupId,
			@ModelAttribute("page") Pagination page,
			Model model){
		String name = getRequest().getParameter("name")==null||getRequest().getParameter("name").trim().length()<=0?"":getRequest().getParameter("name");
		String loginName = getRequest().getParameter("loginName")==null||getRequest().getParameter("loginName").trim().length()<=0?"":getRequest().getParameter("loginName");
		String email = getRequest().getParameter("email")==null||getRequest().getParameter("email").trim().length()<=0?"":getRequest().getParameter("email");
		page = baseUserService.findUserByGroup(name,loginName,email,groupId, page,false);
		model.addAttribute("name", name);
		model.addAttribute("loginName", loginName);
		model.addAttribute("email", email);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName(getViewNamedPath("list"));
		return modelAndView;
	}
	
}
